import { defineStore } from "pinia";
import { UserState } from "@/stores/interface";
import { useRouter } from "vue-router";
export const useUserStore = defineStore({
  id: "user",
  state: (): UserState => ({
    token: "",
    userInfo: null
  }),
  getters: {},
  actions: {
    // Set Token
    setToken(token: string) {
      this.token = token;
    },
    // Set setUserInfo
    setUserInfo(userInfo: UserState["userInfo"]) {
      this.userInfo = userInfo;
    },
    //退出登录
    logout() {
      this.setToken("");
      this.setUserInfo(null);
      window.location.href = "/";
      const router = useRouter();
      router.push("/login");
    }
  },
  persist: true
});
